clear
rng default

%% Part 1

%%%%%%%%  True and Logit values %%%%%%%%
%%% Load
fp0='.../r3/[5]/Compose';
[U, V, Phi, ~, ~, ~]=load_function_CS(fp0);

%%% Fill
tab_temp1=fill_function_CS(U,V,Phi);


%%%%%%%%  Restrictions 1 %%%%%%%%
%%% Load
[U_1, U_2, U_3, V_1, V_2, V_3, Phi, ~, ~, ~]=load_function(fp0);

%%% Fill
tab_temp2=fill_function(U_1, U_2, U_3, V_1, V_2, V_3, Phi);

%%%%%%%%  Restrictions 2 %%%%%%%%
%%% Load
fp0='.../r3/[6]/Compose';
[U_1, U_2, U_3, V_1, V_2, V_3, Phi, ~, ~, ~]=load_function(fp0);

%%% Fill
tab_temp3=fill_function(U_1, U_2, U_3, V_1, V_2, V_3, Phi);


%%%%%%% Combine %%%%%%%%
tab_part1=cell(9,9);
tab_part1(1,:)=tab_temp1(1,:);
tab_part1(2,:)=tab_temp2(1,:);
tab_part1(3,:)=tab_temp3(1,:);
tab_part1(4,:)=tab_temp1(2,:);
tab_part1(5,:)=tab_temp2(2,:);
tab_part1(6,:)=tab_temp3(2,:);
tab_part1(7,:)=tab_temp1(3,:);
tab_part1(8,:)=tab_temp2(3,:);
tab_part1(9,:)=tab_temp3(3,:);
    

%%%%%%% Generate Latex table %%%%%%%%
n_digits=2;
for i=1:9
    for j=1:9
        tab_part1{i,j}= round(tab_part1{i,j},n_digits);
        tab_part1{i,j}=mat2str(tab_part1{i,j});
    end
end
matrix2latex(tab_part1,'tab1.tex','alignment', 'c', 'format', '%1.1f', 'size', 'tiny');



%% Part 2
clear 
%%%%%%%%  True and Logit values %%%%%%%%
%%% Load
fp0='.../r3/[5]/Compose';
[~, ~, ~, D, C_m, C_w]=load_function_CS(fp0);

%%% Fill
tab_temp1=fill_function_CS_part2(D, C_m, C_w);


%%%%%%%%  Restrictions 1 %%%%%%%%
%%% Load
[~, ~, ~, ~, ~, ~, ~, D, C_m, C_w]=load_function(fp0);

%%% Fill
tab_temp2=fill_function_part2(D, C_m, C_w);


%%%%%%%%  Restrictions 2 %%%%%%%%
%%% Load
fp0='.../r3/[6]/Compose';
[~, ~, ~, ~, ~, ~, ~, D, C_m, C_w]=load_function(fp0);

%%% Fill
tab_temp3=fill_function_part2(D, C_m, C_w);


%%%%%%% Combine %%%%%%%%
tab_part2=cell(3,6);
tab_part2(1,:)=tab_temp1;
tab_part2(2,:)=tab_temp2;
tab_part2(3,:)=tab_temp3;

    

%%%%%%% Generate Latex table %%%%%%%%
n_digits=2;
for i=1:3
    for j=1:6
        tab_part2{i,j}= round(tab_part2{i,j},n_digits);
        tab_part2{i,j}=mat2str(tab_part2{i,j});
    end
end
matrix2latex(tab_part2,'tab2.tex','alignment', 'c', 'format', '%1.1f', 'size', 'tiny');





